<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
              <div class="fieldBox" >
                <div class="label">品牌</div>
                <div class="field">
                  <input name="brCd" id="brCd" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">车系</div>
                <div class="field">
                    <input name="carModel" id="carModel" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox"  >
                <div class="label"> 车辆用途：</div>
                <div class="field">
                    <input name="carUsage" id="carUsage" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox"   >
                <div class="label"> 车型：</div>
	              <div class="field">
                      <input name="carStyle" id="carStyle" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                  </div>
            </div>

            <div class="fieldBox" >
                <div class="label">公告型号</div>
                <div class="field">
                    <input name="styleBulletinModel" id="styleBulletinModel" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">车型ID</div>
                <div class="field">
                    <input name="styleId" id="styleId" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
              <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	var prjId= '${prjId}';
	var brandComboBox = null;
	var carModelComboBox = null ;
	var carStyleComboBox = null ;
	var carUsageComboBoxLv1 = null;
	var carUsageComboBoxLv2 = null;
	// 是否拥有改变品牌和车系的权限，1是0否
	var auth = ${auth};
	$(function () {
		// 初始化品牌下拉
        initBrand();
        initCarModel();
        initCarStyle();
        carStyleComboBox = liger.get("carStyle");
        carStyleComboBox.setDisabled(true);
        initCarUsageLv2();
        carUsageComboBoxLv2 = liger.get("carUsage");
	});

    /**
     * 初始化品牌下拉信息
     */
	function initBrand(){
        $("#brCd").ligerComboBox({
            url: '<%=path%>/project/vehicle/brand.do',
            ajaxType: "get",
            parms:{str:"1"},
            width: 120,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {

                // 重新加载车系
                initCarModel();
                if(carModelComboBox){
                    carModelComboBox.setValue("")
                }
                // 清空车型选择
                if(carStyleComboBox){
                    carStyleComboBox.setValue("");
                    carStyleComboBox.setDisabled(true);
                }
                //清空用途
               if(carUsageComboBoxLv2){
                   carUsageComboBoxLv2.setValue("");
                   carUsageComboBoxLv2.setDisabled(true);
               }

            },
         onSuccess:function(){
             brandComboBox = liger.get("brCd")
                var brCd = "${brCd}";
                 if(brCd){
                     var findValueByText = brandComboBox.findValueByText(brCd);
                     brandComboBox.setValue(findValueByText);
                     if(auth == "0"){
                         brandComboBox.setDisabled(true);
                     }
                 }
         }
        });
    }

    /**
     *  初始化车系下拉
     *  必须选择了品牌才会真正加载内容
     */
    function initCarModel(){
        var url = null;
        var brandId = null ;
        if(brandComboBox){
            if(brandComboBox.getValue()){
                url = '<%=path%>/project/vehicle/carModel.do'
                brandId = brandComboBox.getValue();
            }
        }
        $("#carModel").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{brandId:brandId},
            width: 120,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                //重载用途2级
                initCarUsageLv2();
                if(carUsageComboBoxLv2){
                    carUsageComboBoxLv2.setEnabled(true);
                    carUsageComboBoxLv2.setValue("");
                }

                // 清空车型
                if(carStyleComboBox){
                    carStyleComboBox.setDisabled(true);
                    carStyleComboBox.setValue("");
                }
            },
            onsuccess:function(){
                carModelComboBox = liger.get("carModel")
                var modelName = "${modelName}";
                if(modelName){
                    var findValueByText = carModelComboBox.findValueByText(modelName);
                    carModelComboBox.setValue(findValueByText);
                    if(auth == "0"){
                        carModelComboBox.setDisabled(true);
                    }
                }
                prdGrid();
            }
        });
    }
    /**
     * 初始化车型下拉
     * 必须选择了车系才会加载
     */
    function initCarStyle(brandId){
        var url = null;
        var brandId = null;
        var carModelId = null;
        var purpose = null ;
        if(carModelComboBox){
            if(carModelComboBox.getValue()){
                url = '<%=path%>/project/vehicle/carStyle.do'
                brandId = brandComboBox.getValue();
                carModelId = carModelComboBox.getValue();
                purpose = carUsageComboBoxLv2.getValue();
            }
        }
        $("#carStyle").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{brandId:brandId,carModelId:carModelId,purpose:purpose},
            width: 430,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {

            }
        });
    }
    /**
     * 初始化车辆用途一级类
     * 必须选择了车型才会加载
     */
    function initCarUsageLv1(){
        var url = null;
        var modelId = null;
        if(carModelComboBox){
            if(carModelComboBox.getValue()){
                modelId = getComboBoxValue(carModelComboBox);
                url = '<%=path%>/project/vehicle/carUsageLv1.do'
            }
        }

        $("#carUsageLv1").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{modelId:modelId},
            width: 140,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                // 打开车辆用途
                initCarUsageLv2();
                carUsageComboBoxLv2.setEnabled(true);
            }
        });
    }
    /**
     * 初始化车辆用途LV2
     * 必须选择了车型才会加载
     */
    function initCarUsageLv2(){
        var url = null;
        var modelId = null;
        if(carModelComboBox){
            if(carModelComboBox.getValue()){
                modelId = carModelComboBox.getValue();
                url = '<%=path%>/project/vehicle/carUsage.do'
            }
        }
        var lv1 = null;
        if(carUsageComboBoxLv1){
            lv1 = carUsageComboBoxLv1.getValue();
        }
        $("#carUsage").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{lv1:lv1,modelId:modelId},
            width: 140,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                // 清空车型
                initCarStyle();
                if(carStyleComboBox){
                    carStyleComboBox.setEnabled(true);
                    carStyleComboBox.setValue("");
                }
            }
        });
    }

    /**
     * 获取comboBox的值
     * @param comboBox
     * @returns {null}
     */
    function getComboBoxValue(comboBox){
        if(comboBox){
            var selected = comboBox.getValue();
            if(selected){
                return selected;
            }
        }
        return null;
    }
	//根据产品类型加载不同的grid
	function prdGrid(prdType,parms){
        // 品牌id
        var brandId = getComboBoxValue(brandComboBox);
        // 车系id
        var modelId = getComboBoxValue(carModelComboBox);
        // 车型id
        var styleId = getComboBoxValue(carStyleComboBox);
        // 用途id
        var usageId =  getComboBoxValue(carUsageComboBoxLv2);
        // 公告型号
        var styleBulletinModel = $("#styleBulletinModel").val();

        // 车型ID
        var styleId2 = $("#styleId").val();
        if(StringUtils.isNotEmpty(styleId2)){
            styleId = styleId2;
        }
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/project/vehicle/initList.do',
            method : 'get',
            parms : {makeId:brandId,modelid:modelId,id:styleId,stylePurposeId:usageId,styleBulletinModel:styleBulletinModel},
            columns: [
                { display: '车型名称', name: 'styleName', minWidth: 150 ,
                    enabledSort:true},
                { display: '车型ID', name: 'id', minWidth: 150 ,
                    enabledSort:true},
                { display: '产品名称', name: 'stylePurposeName', minWidth: 150 ,
                    enabledSort:true},
                { display: '参考价', name: 'styleMsrp', width: 100,
                    render: function (rowdata, rowindex, value, column) {
                        if(value){
                            var h = value/100;
                            return h;
                        }
                    },
                    enabledSort:true
                },
                // { display: '产品类型', name: 'stylePurposeId', minWidth: 150 , enabledSort:true},
                { display: '驱动形式', name: 'styleDriveMode', minWidth: 100 , enabledSort:true},
                { display: '发动机型号', name: 'styleEngine', minWidth: 140 , enabledSort:true},
                { display: '操作', name: 'styleStatus', width: 50, enabledSort:true,render: function (rowdata, rowindex, value){
                        var h='<a class="sq-button-hasicon" href="javascript:choosePrdRow(';
                        h+="'"+rowdata.id+"',";
                        if(rowdata.styleBulletinModel){
                            h+="'"+rowdata.styleBulletinModel+"',";
                        }else{
                            h+="' ',";
                        }
                        if(rowdata.styleEngine){
                            h+="'"+rowdata.styleEngine+"',";
                        }else{
                            h+="' ',";
                        }
                        if(rowdata.prdId){
                            h+="'',";
                        }else{
                            h+="' ',";
                        }
                        if(rowdata.styleLength){
                            h+="'"+rowdata.styleLength+"',";
                        }else{
                            h+="'',";
                        }
                        if(rowdata.basicNseats){
                            h+="'"+rowdata.basicNseats+"',";
                        }else{
                            h+="'',";
                        }
                        if(rowdata.styleBulletinModel){
                            h+="'"+rowdata.styleBulletinModel+"',";//产品型号
                        }else{
                            h+="' ',";
                        }
                        if(rowdata.id){
                            h+="'"+rowdata.id+"',";
                        }else{
                            h+="'',";
                        }
                        if(rowdata.stylePurposeId){
                            h+="'"+rowdata.stylePurposeId+"',";
                        }else{
                            h+="'',";
                        }
                        if(rowdata.styleLength){
                            h+="'"+rowdata.styleLength+"'";
                        }else{
                            h+="''";
                        }

                        h+=')"><i class="sqBtnIco_3"></i>选择</a>'
                        return h;
                    }}
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            //isScroll: false,
            checkbox:true,
            rownumbers:true
        });
		grid = liger.get("ligergrid1");
	}

	function searchBtn(){
        var selected = "";
        if(brandComboBox){
            selected = brandComboBox.getValue();
        }
        var selected2 = "";
        if(carModelComboBox){
            selected2 = carModelComboBox.getValue();
        }
        if(selected){ //如果选了品牌 必须选车系
            if(!selected2){
                alert("请选择车系")
                return;
            }
        }
       prdGrid();
	}

    function choosePrdRow(detailId,prdMdl,engMdl,prdId,carLen,seatQtyCd,dtlprdMdl,styleId,stylePurposeId,styleLength){
        // TODO 传用途代码回去  用来保存 不然没地方拿到用途代码
        parent.window.document.getElementById("prdCd").value=stylePurposeId;
        parent.window.document.getElementById("detailId").value=detailId;
        if(!detailId){
            detailId = "";
        }
        if(!prdMdl||prdMdl=='null'){
            prdMdl = "";
        }
        //品牌
        if(parent.window.document.getElementById("brCd") && brandComboBox && brandComboBox.getText()){
        	parent.window.document.getElementById("brCd").value=brandComboBox.getText();
        }
     	 //车系
        if(parent.window.document.getElementById("modelName") && carModelComboBox && carModelComboBox.getText()){
        	parent.window.document.getElementById("modelName").value=carModelComboBox.getText();
        }
        if(parent.window.document.getElementById("prdMdl")){
            parent.window.document.getElementById("prdMdl").value=prdMdl;//车型
        }
        if(parent.window.document.getElementById("carLen")){
            $(parent.window.document.getElementById("carLen")).val(styleLength)
        }
        if(styleLength){
            if(styleLength < 5700 ){
                $(parent.window.document.getElementById("prdLvlCd")).val("轻型客车")
            }else if(styleLength >= 10000){
                $(parent.window.document.getElementById("prdLvlCd")).val("大型客车")
            }else{
                $(parent.window.document.getElementById("prdLvlCd")).val("中型客车")
            }
        }
        $(parent.window.document.getElementById("carLen")).trigger("change");
        if(!engMdl||engMdl=='null'){
            engMdl = "";
        }
        var engMdlElement = parent.window.document.getElementById("engMdl");
        if(engMdlElement){
            engMdlElement.value=engMdl;//发动机型号
        }

        var styleIdInput = parent.window.document.getElementById("styleId");
        if(styleIdInput){
            styleIdInput.value=styleId;
        }
        if(!carLen||carLen=='null'){
            carLen = "";
        }
        if(parent.window.document.getElementById("carLen")){
            parent.window.document.getElementById("carLen").value=carLen;//车身长度
        }

        if(!seatQtyCd||seatQtyCd=='null'){
            seatQtyCd = "";
        }
        if(parent.window.document.getElementById("seatQtyCd")){
            parent.window.document.getElementById("seatQtyCd").value=seatQtyCd;//座位数
        }
        if(!dtlprdMdl||dtlprdMdl=='null'){
            dtlprdMdl = "";
        }
        if(parent.window.document.getElementById("dtlprdMdl")){
            parent.window.document.getElementById("dtlprdMdl").value=dtlprdMdl;//产品型号
        }
        parent.changeCallBack(styleId);
        parent.$.ligerDialog.close();
        parent.$(".l-dialog,.l-window-mask").css("display","none");
    }

	function clearBtn(){
        if(auth=="1"){
            brandComboBox.setValue("");
            carModelComboBox.setValue("")
        }
        carStyleComboBox.setValue("")
        carUsageComboBoxLv2.setValue("")
        carUsageComboBoxLv1.setValue("")
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }


</script>

</body>
</html>